<template>
  <div class="mod-config">
      <el-tabs type="border-card" v-model="tabValue" @tab-click="tabChange">
        <el-button-group style="margin-bottom: 10px;">
          <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询</el-button>
          <el-button type="primary" icon="el-icon-delete" @click="searchReset">清空</el-button>
        </el-button-group>
        <el-tab-pane label="未收货委外订单" name="tab1">
          <el-form inline label-width="100px"  @keyup.enter.native="searchHandle">
            <el-form-item label="配镜单号">
              <el-input v-model="dataForm.saleBillId"></el-input>
            </el-form-item>
            <el-form-item label="制造商">
              <el-select v-model="dataForm.supplyId" clearable filterable default-first-option>
                <el-option v-for="item in supplyOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="部门">
              <el-select v-model="dataForm.deptId" clearable>
                <el-option v-for="item in deptOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="顾客姓名">
              <el-input v-model="dataForm.customerName"></el-input>
            </el-form-item>
            <el-form-item label="配镜日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.saleTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.saleTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="取镜日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.takeMirroTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.takeMirroTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="配镜类型">
              <el-select v-model="dataForm.consignType">
                <el-option value="1" label="隐形订做片"></el-option>
                <el-option value="2" label="框镜订做片"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品名称">
              <el-input v-model="dataForm.viewGoodsName"></el-input>
            </el-form-item>
            <el-form-item label="球镜">
              <el-input v-model="dataForm.mirrorBall"></el-input>
            </el-form-item>
            <el-form-item label="柱镜">
              <el-input v-model="dataForm.columnMirror"></el-input>
            </el-form-item>
          </el-form>
            <div class="avue-crud">
              <el-table :data="firstList" border v-loading="dataListLoading" :max-height="tableHeight1" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="30"></el-table-column>
                <el-table-column prop="saleBillId" label="配镜单号" width="150">
                  <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="customerName" label="顾客姓名" width="120"></el-table-column>
                <el-table-column prop="customerPhone" label="顾客电话" width="120"></el-table-column>
                <el-table-column prop="deptName" label="销售部门" width="120"></el-table-column>
                <el-table-column prop="supplyName" label="制造商" width="160"></el-table-column>
                <el-table-column prop="saleType" label="配镜类型" width="80">
                  <template slot-scope="scope">
                    <!-- 1-隐形订做,2-框镜订做,3-隐形成品,4-框镜成品,5-辅料-->
                    {{getSaleType(scope.row.consignType)}}
                  </template>
                </el-table-column>
                <el-table-column prop="saleTime" label="配镜时间" width="140"></el-table-column>
                <el-table-column prop="takeMirroTime" label="取镜时间" width="140"></el-table-column>
                <el-table-column label="操作" fixed="right">
                  <template slot-scope="scope">
                    <el-button v-if="permissions.eims_consign_add" type="text" icon="el-icon-edit" @click="openDialogConsignAdd(scope.row.consignId)">委外收货</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          <div class="avue-crud__pagination">
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100, 200]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
            </el-pagination>
          </div>
        </el-tab-pane>

        <el-tab-pane label="未收货委外重订单" name="tab2">
          <el-form :inline="true" :model="dataForm" @keyup.enter.native="searchHandle">
            <el-form-item label="委外订单">
              <el-input v-model="dataForm.reSaleBillId"></el-input>
            </el-form-item>
            <el-form-item label="制造商">
              <el-select v-model="dataForm.supplyId" clearable filterable default-first-option>
                <el-option v-for="item in supplyOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="部门">
              <el-select v-model="dataForm.deptId">
                <el-option v-for="item in deptOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="顾客姓名">
              <el-input v-model="dataForm.customerName"></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="dataForm.memo"></el-input>
            </el-form-item>
            <el-form-item label="配镜日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.saleTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.saleTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="取镜日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.takeMirroTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.takeMirroTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="配镜类型">
              <el-select v-model="dataForm.consignType">
                <el-option value="1" label="隐形订做片"></el-option>
                <el-option value="2" label="框镜订做片"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品名称">
              <el-input v-model="dataForm.viewGoodsName"></el-input>
            </el-form-item>
            <el-form-item label="球镜">
              <el-input v-model="dataForm.mirrorBall"></el-input>
            </el-form-item>
            <el-form-item label="柱镜">
              <el-input v-model="dataForm.columnMirror"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">搜索</el-button>
              <el-button icon="el-icon-delete" @click="searchReset">清空</el-button>
            </el-form-item>
          </el-form>
          <div class="avue-crud">
            <div class="avue-crud">
              <el-table :data="secondList" height="calc(100vh - 215px)" border v-loading="dataListLoading" @selection-change="handleSelectionChange" :max-height="tableHeight2">
                <el-table-column type="selection" width="40"></el-table-column>
                <el-table-column prop="reSaleBillId" label="委外重订单单号" width="150">
                  <!-- <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
                  </template> -->
                </el-table-column>
                <el-table-column prop="customerName" label="顾客姓名" width="120"></el-table-column>
                <el-table-column prop="customerPhone" label="顾客电话" width="120"></el-table-column>
                <el-table-column prop="deptName" label="销售部门" width="120"></el-table-column>
                <el-table-column prop="supplyName" label="制造商" width="160"></el-table-column>
                <el-table-column label="配镜类型" width="80">
                  <template slot-scope="scope">
                    <!-- 1-隐形订做,2-框镜订做,3-隐形成品,4-框镜成品,5-辅料-->
                    {{getSaleType(scope.row.consignType)}}
                  </template>
                </el-table-column>
                <el-table-column prop="saleTime" label="配镜时间" width="140"></el-table-column>
                <el-table-column prop="takeMirroTime" label="取镜时间" width="140"></el-table-column>
                <el-table-column label="操作" fixed="right">
                  <template slot-scope="scope">
                    <el-button v-if="permissions.eims_consign_add" type="text" icon="el-icon-edit" @click="openDialogConsignAdd(scope.row.consignId)">委外收货</el-button>
                    <el-button v-if="permissions.eims_consign_del" type="text" icon="el-icon-edit" @click="delConsignAgain(scope.row)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>

          </div>
          <div class="avue-crud__pagination" style="margin-bottom: 15px;">
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
              :page-sizes="[10, 20, 50, 100, 200]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
          </div>
        </el-tab-pane>

        <el-tab-pane label="已收货委外订单" name="tab3">
          <el-form :inline="true" :model="dataForm" @keyup.enter.native="searchHandle">
            <el-form-item label="单据编号">
              <el-input v-model="dataForm.billId"></el-input>
            </el-form-item>
            <el-form-item label="配镜单号">
              <el-input v-model="dataForm.saleBillId"></el-input>
            </el-form-item>
            <el-form-item label="制单日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.createTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.createTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="制造商">
              <el-input v-model="dataForm.supplyName" @change="changeSupplyId">
                <el-button slot="append" @click="openSupplyDialog">选择</el-button>
              </el-input>
            </el-form-item>
            <el-form-item label="审核状态">
              <el-select v-model="dataForm.auditStatus">
                <el-option value="0" label="未审核"></el-option>
                <el-option value="1" label="已审核"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单据类型">
              <el-select v-model="dataForm.saleType">
                <el-option value="1" label="隐形订做片"></el-option>
                <el-option value="2" label="框镜订做片"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="顾客姓名">
              <el-input v-model="dataForm.customerName"></el-input>
            </el-form-item>
            <el-form-item label="制单人">
              <el-input v-model="dataForm.createUserName"></el-input>
            </el-form-item>
            <el-form-item label="审核人">
              <el-input v-model="dataForm.auditUserName"></el-input>
            </el-form-item>
            <el-form-item label="审核日期">
              <el-row>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.auditTimeStart" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
                <el-col class="line" :span="2" style="text-align: center;">-</el-col>
                <el-col :span="11">
                  <el-date-picker v-model="dataForm.auditTimeEnd" style="width: 100%;" value-format="yyyy-MM-dd"></el-date-picker>
                </el-col>
              </el-row>
            </el-form-item>
            <el-form-item label="收入仓位">
              <el-select v-model="dataForm.inStockId">
                <el-option v-for="item in stockOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="商品名称">
              <el-input v-model="dataForm.viewGoodsName"></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="dataForm.memo"></el-input>
            </el-form-item>
            <el-form-item label="是否显示收货商品数量">
              <el-checkbox v-model="dataForm.countShowFlag">显示</el-checkbox>
            </el-form-item>

            <div v-if="this.dataForm.countShowFlag">
              <el-divider content-position="left">统计商品数量补充条件</el-divider>
              <el-form-item label="商品类别">
                <el-select v-model="dataForm.ctgId" @change="changeCtgId">
                  <el-option v-for="item in ctgOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="收货商品品种" prop="brandName">
                <el-input v-model="dataForm.brandName" readonly="readonly">
                  <el-button slot="append" @click="getBrandList">选择</el-button>
                </el-input>
              </el-form-item>
              <el-form-item label="部门">
                <el-select v-model="dataForm.deptId">
                  <el-option v-for="item in deptOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
                </el-select>
              </el-form-item>
            </div>

            <el-form-item>
              <el-form-item>
                <el-button type="primary" size="mini" icon="el-icon-search" @click="searchHandle">搜索</el-button>
                <el-button size="mini" icon="el-icon-delete" @click="searchReset">清空</el-button>
              </el-form-item>
              <!--<el-button v-if="permissions.eims_inventory_add" icon="el-icon-plus" type="primary" size="mini" @click="openDialogAddUpdate()">新增委外订单</el-button>-->
            </el-form-item>
          </el-form>
          <div v-if="this.dataForm.countShowFlag">
            <el-row style="margin-bottom: 15px;">
              委外收货商品数量总计：{{ sum }}
            </el-row>
          </div>
          <div class="avue-crud">
            <el-table :data="thirdList" height="calc(100vh - 215px)" border v-loading="dataListLoading"
              @selection-change="handleSelectionChange" :max-height="tableHeight3">
              <el-table-column type="selection" width="40"></el-table-column>
              <el-table-column prop="billId" label="单据编号" width="160"></el-table-column>
              <el-table-column prop="saleBillId" label="配镜单号" width="150">
                <template slot-scope="scope">
                  <el-button type="text" @click="checkDetailByOrder(scope.row.saleBillId)">{{scope.row.saleBillId}}</el-button>
                </template>
              </el-table-column>
              <el-table-column label="配镜类型" width="80">
                <template slot-scope="scope">
                  <!-- 1-隐形订做,2-框镜订做,3-隐形成品,4-框镜成品,5-辅料-->
                  {{getSaleType(scope.row.saleType)}}
                </template>
              </el-table-column>
              <el-table-column prop="supplyName" label="制造商"></el-table-column>
              <el-table-column prop="inStockName" label="收入仓位" width="120"></el-table-column>
              <el-table-column prop="createUserName" label="制单人" width="70"></el-table-column>
              <el-table-column prop="createTime" label="制单日期" width="135"></el-table-column>
              <el-table-column prop="auditUserName" label="审核人" width="70"></el-table-column>
              <el-table-column prop="auditTime" label="审核时间" width="135"></el-table-column>
              <el-table-column prop="memo" label="备注" show-overflow-tooltip></el-table-column>
              <el-table-column label="操作" width="90" fixed="right">
                <template slot-scope="scope">
                  <el-button type="text" size="small" icon="el-icon-info" @click="openDialogReceiptInfo(scope.row.id)">查看详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="avue-crud__pagination" style="margin-bottom: 15px;">
            <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
              :page-sizes="[10, 20, 50, 100,200]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
            </el-pagination>
          </div>
        </el-tab-pane>
      </el-tabs>
      <!-- 弹窗, 生成委外收货订单 /  -->
      <receipt-add v-if="receiptAddVisible" ref="receiptAdd" @refreshDataList="getDataList"></receipt-add>
      <!--委外收货订单详情-->
      <receipt-info v-if="receiptInfoVisible" ref="receiptInfo" @refreshDataList="getDataList"></receipt-info>
      <!-- 弹窗, 批量生成委外订单 -->
      <!-- <outsource-batch v-if="outsourceBatchVisible" ref="outsourceBatch" @refreshDataList="getDataList"></outsource-batch>-->
      <!-- 弹窗, 新增 / 修改委外订单 -->
      <add-update v-if="addUpdateVisible" ref="addUpdate" @refreshDataList="getDataList"></add-update>
      <!-- 弹窗，制造商选择 -->
      <search-supply v-if="supplyVisible" ref="supplyDialog" @refreshData="getSupplyData"></search-supply>
      <!-- 弹窗，查询商品品种 -->
      <select-brand v-if="selectBrandVisible" ref="selectBrand" @refreshData="updateFormBrand"></select-brand>
      <!-- 弹窗，查看配镜单详情 -->
      <order-info v-if="infoVisible" ref="infoDialog"></order-info>

  </div>
</template>

<script>
  import { remote } from '@/api/admin/dict'
  import { getUnConsignReceiptByPage, getReceiptByPage, getGoodsNumberSum, delDeliveryObj } from '@/api/eims/consign/consignReceipt.js'
  import { getAllConsignSupply } from '@/api/eims/supply'
  // 弹窗， 生成委外订单
  import ReceiptAdd from './receipt-add.vue'
  //弹窗， 查看委外订单详情
  import ReceiptInfo from './receipt-info.vue'
  //弹窗，制造商选择
  import SearchSupply from '@/components/business/SearchSupply'
  //  弹窗，查看配镜单详情
  import OrderInfo from '@/views/eims/optician/glassesinfo/detail'

  import { getStockList } from '@/api/eims/stock'
  import { getCtgList } from '@/api/eims/ctg'
  import SelectBrand from './SearchBrand'
  import { getDeptInfo } from '@/api/admin/dept'

  import { mapGetters } from 'vuex'
  export default {
    data() {
      return {
        tabValue: 'tab1',
        dataForm: {
          saleBillId: '',
          supplyName: '',
          brandName: '',
        },
        firstList: [],
        secondList: [],
        thirdList: [],
        saleTypeData: [],
        pageIndex: 1,
        pageSize: 200,
        totalPage: 0,
        dataListLoading: false,
        sum: '',
        orderList: [],
        supplyOptions: [],
        deptOptions: [],
        receiptAddVisible: false,
        receiptInfoVisible: false,
        outsourceBatchVisible: false,
        addUpdateVisible: false,
        supplyVisible: false,
        infoVisible: false,
        stockOptions: [],
        selectBrandVisible: false,
        ctgOptions: [],

      }
    },
    components: {
      ReceiptAdd, //委外订单新增页面
      ReceiptInfo, //委外订单详情页面
      SearchSupply,
      SelectBrand,
      OrderInfo
    },
    created() {
      this.getDataList()
      this.getStock()
      this.getGoodsCtgList()
      this.getDeptList()
      this.getSupply()
      remote('sale_type').then(result => {
        this.saleTypeData = result.data.data
      })
    },
    computed: {
      ...mapGetters(['permissions', 'bizData', 'userInfo']),
      tableHeight1: function(){
        return window.innerHeight - 260
      },
      tableHeight2: function(){
        return window.innerHeight - 260
      },
      tableHeight3: function(){
        return window.innerHeight - 260
      }
    },
    methods: {
      tabChange(data) {
        for (let key in this.dataForm) {
          this.dataForm[key] = ''
        }
        this.pageIndex = 1
        this.totalPage = 0
        this.firstList = []
        this.secondList = []
        this.thirdList = []
        this.getSupply()
        this.getDataList()
      },
      //  查询数据
      searchHandle() {
        this.pageIndex = 1
        this.getDataList()
      },
      //  获取数据列表
      getDataList() {
        let params1 = {
          current: this.pageIndex,
          size: this.pageSize
        }

        this.dataListLoading = true

        if (this.tabValue == 'tab1') {
          this.dataForm.reorderFlag = '0'
          let params2 = this.filterParams(this.dataForm)
          getUnConsignReceiptByPage(Object.assign(params1, params2)).then(response => {
            if(response.data.code == '0'){
              this.firstList = response.data.data.records
              this.totalPage = response.data.data.total
            }else{
              this.$message.error(response.data.msg)
            }
            this.dataListLoading = false
          })
        } else if (this.tabValue == 'tab2') {
          this.dataForm.reorderFlag = '1'
          let params2 = this.filterParams(this.dataForm)
          getUnConsignReceiptByPage(Object.assign(params1, params2)).then(response => {
            if(response.data.code == '0'){
              this.secondList = response.data.data.records
              this.totalPage = response.data.data.total
            }else{
              this.$message.error(response.data.msg)
            }
            this.dataListLoading = false
          })
        } else if (this.tabValue == 'tab3') {
          let params2 = this.filterParams(this.dataForm)
          getReceiptByPage(Object.assign(params1, params2)).then(response => {
            if(response.data.code == '0'){
              this.thirdList = response.data.data.records
              this.totalPage = response.data.data.total
            }else{
              this.$message.error(response.data.msg)
            }
            this.dataListLoading = false
          })
          getGoodsNumberSum(this.dataForm).then(result => {
            this.sum = result.data.data
          })
        }

      },
      // 每页显示条数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      handleSelectionChange(val) {
        this.orderList = val
      },
      // 打开弹窗, 生成委外订单
      openDialogConsignAdd(id) {
        this.receiptAddVisible = true
        this.$nextTick(() => {
          this.$refs.receiptAdd.init(id)
        })
      },
      // 打开弹窗, 查看委外订单详情
      openDialogReceiptInfo(id) {
        this.receiptInfoVisible = true
        this.$nextTick(() => {
          this.$refs.receiptInfo.init(id)
        })
      },
      //  打开弹窗，查看配镜单详情
      checkDetailByOrder(order) {
        this.infoVisible = true;
        this.$nextTick(() => {
          this.$refs.infoDialog.init('', order, '配镜单详情');
        });
      },
      //获取配镜类型枚举
      getSaleType(value) {
        let obj = {};
        obj = this.saleTypeData.find((item) => {
          return item.value == value;
        });
        if (obj && obj.label) {
          return obj.label;
        }
      },
      // 打开弹窗, 批量生成委外订单
      /*   openDialogOutsourceBatch() {
           if(this.orderList.length) {
             let list = []
             this.orderList.forEach(item => {
               if(list.indexOf(item.supply) == -1){
                 list.push(item)
               }
             })
             if(list.length > 1) {
               this.$message.warning('请选择相同的制造商进行批量生成委外订单')
               return false
             }
             this.outsourceBatchVisible = true
             this.$nextTick(() => {
               this.$refs.outsourceBatch.init()
             })
           }else{
             this.$message.warning('请选择配镜单')
           }
         },*/
      // 打开弹窗， 新增 / 修改 委外订单
      openDialogAddUpdate(id) {
        this.addUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addUpdate.init(id)
        })
      },
      // 打开采购订单弹窗
      orderReceiveGoods(id) {
        this.receiveGoodsVisible = true
        this.$nextTick(() => {
          this.$refs.receiveGoods.init(id)
        })
      },
      // 搜索清空
      searchReset() {
        for (let key in this.dataForm) {
          this.dataForm[key] = ''
        }
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 隐形新增
      addOrUpdateHandleInvisible() {
        this.invisibleFormVisible = true
        this.$nextTick(() => {
          this.$refs.invisibleForm.init()
        })
      },
      //   打开制造商选择弹窗
      openSupplyDialog() {
        this.supplyVisible = true
        this.$nextTick(() => {
          if (this.dataForm.ctgId) {
            this.$refs.supplyDialog.init({
              ctgId: this.dataForm.ctgId
            })
          } else {
            this.$refs.supplyDialog.init({
              ctgId: ''
            })
          }

        })
      },
      //   获取制造商信息
      getSupplyData(data) {
        this.$set(this.dataForm, 'supplyName', data.name)
        this.$set(this.dataForm, 'supplyId', data.id)
      },
      changeSupplyId() {
        // this.dataForm.brandId = ''
        // this.dataForm.brandName= ''
      },
      //  获取仓位列表
      getStock() {
        getStockList().then(result => {
          if(result.data.code == '0'){
            this.stockOptions = result.data.data
          }else{
            this.$message.error(result.data.msg)
          }
        })
      },
      getSupply() {
        let reorderFlag = '';
        if (this.tabValue == 'tab1') {
          reorderFlag = '0';
          getAllConsignSupply(reorderFlag).then(result => {
            if(result.data.code == '0'){
              this.supplyOptions = result.data.data
            }else{
              this.$message.error(result.data.msg)
            }
          })
        } else if (this.tabValue == 'tab2') {
          reorderFlag = '1';
          getAllConsignSupply(reorderFlag).then(result => {
            if(result.data.code == '0'){
              this.supplyOptions = result.data.data
            }else{
              this.$message.error(result.data.msg)
            }  
          })
        }
      },
      //  获取商品类别
      getGoodsCtgList() {
        getCtgList().then(result => {
          if(result.data.code == '0'){
            this.ctgOptions = result.data.data
          }else{
            this.$message.error(result.data.msg)
          }  
        })
      },
      changeCtgId() {
        this.dataForm.supplyId = ''
        this.dataForm.supplyName = ''
        // this.dataForm.brandId = ''
        // this.dataForm.brandName= ''
      },
      // 获取商品品种信息
      getBrandList() {
        // if (!this.dataForm.ctgId) {
        //   this.$message.warning('请选择商品类别')
        //   return false
        // }
        // if (!this.dataForm.supplyId) {
        //   this.$message.warning('请选择制造商')
        //   return false
        // }
        let data = {
          ctgId: this.dataForm.ctgId,
          supplyId: this.dataForm.supplyId
        }
        this.selectBrandVisible = true
        this.$nextTick(() => {
          this.$refs.selectBrand.init(data)
        })
      },
      //  更新表单品种信息
      updateFormBrand(data) {
        this.dataForm.brandId = data.id
        this.dataForm.brandName = data.name
        this.dataForm.brandCode = data.code
        this.dataForm.name = data.name
        this.dataForm.unitType = data.unitType
      },
      //  获取部门列表
      getDeptList() {
        getDeptInfo().then(result => {
          if(result.data.code == '0'){
            this.deptOptions = result.data.data
          }else{
            this.$message.error(result.data.msg)
          } 
        })
      },
      //删除委外重订单
      delConsignAgain(data) {
        this.$confirm("是否确认删除ID为" + data.reSaleBillId, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
          .then(function() {
            return delDeliveryObj(data.consignId);
          })
          .then(result => {
            if(result.data.code == '0'){
              this.$message.success("删除成功");
              this.getDataList();
            }else{
              this.$message.error(result.data.msg)
            } 
          });
      },

    }
  }
</script>
